@ECHO OFF

SET INPUT=%1
SET ROOTDIR=%2
SET TARGETDIR=%3
SET OUTPUT=%ROOTDIR%\%TARGETDIR%
SET HEADER_DIR=
SET LIB_DIR=Binaries

RMDIR /S /Q %OUTPUT%

:CopyLoop
FOR /F "tokens=*" %%A in (%ROOTDIR%\%INPUT%) DO CALL :CheckFile %%A
GOTO :EOF

:CheckFile
SET SOURCE=%1
SET FILE=%~nx1
SET EXTENSION=%~x1
SET DIREXT=""

IF "%EXTENSION%"==".h" (
	CALL :CopyFile %SOURCE% %HEADER_DIR%
) ELSE (
	IF "%EXTENSION%"==".inl" (
		CALL :CopyFile %SOURCE% %HEADER_DIR%
	) ELSE (
		IF "%EXTENSION%"==".dll" (
			CALL :CopyLib %SOURCE% %LIB_DIR%
		) ELSE (
			IF "%EXTENSION%"==".lib" (
				CALL :CopyLib %SOURCE% %LIB_DIR%
			) ELSE (
				ECHO Unknown File Extension: %SOURCE%
			)
		)
	)
)
GOTO :EOF

:CopyLib
SET SOURCE=%1
SET TARGET=%2
ECHO.%SOURCE%| FIND /I "x64">Nul && (
	CALL :CopyFile %SOURCE% %TARGET%\x64
) || (
	ECHO.%SOURCE%| FIND /I "ARM">Nul && (
		CALL :CopyFile %SOURCE% %TARGET%\ARM
	) || (
		ECHO.%SOURCE%| FIND /I "WP8">Nul && (
			CALL :CopyFile %SOURCE% %TARGET%\ARM
		) || (
			ECHO.%SOURCE%| FIND /I "x86">Nul && (
				CALL :CopyFile %SOURCE% %TARGET%\x86
			) || (
				ECHO.%SOURCE%| FIND /I "Win32">Nul && (
					CALL :CopyFile %SOURCE% %TARGET%\x86
				) || (
					ECHO Unknown library type.
				)
			)
		)
	)
)
GOTO :EOF

:CopyFile
SET SOURCE=%1
IF "%~2"=="" (
	SET TARGET=%TARGETDIR%\
) ELSE (
	SET TARGET=%TARGETDIR%\%2\
)
XCOPY /Y "%SOURCE%" "%TARGET%"

GOTO :EOF